package com.ruoyi.Warehouse.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Warehouse.domain.Cardinventory;
import com.ruoyi.Warehouse.service.ICardinventoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 卡牌库存表Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@Controller
@RequestMapping("/pims/cardinventory")
public class CardinventoryController extends BaseController
{
    private String prefix = "pims/cardinventory";

    @Autowired
    private ICardinventoryService cardinventoryService;

    @RequiresPermissions("pims:cardinventory:view")
    @GetMapping()
    public String cardinventory()
    {
        return prefix + "/cardinventory";
    }

    /**
     * 查询卡牌库存表列表
     */
    @RequiresPermissions("pims:cardinventory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Cardinventory cardinventory)
    {
        startPage();
        List<Cardinventory> list = cardinventoryService.selectCardinventoryList(cardinventory);
        return getDataTable(list);
    }

    /**
     * 导出卡牌库存表列表
     */
    @RequiresPermissions("pims:cardinventory:export")
    @Log(title = "卡牌库存表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Cardinventory cardinventory)
    {
        List<Cardinventory> list = cardinventoryService.selectCardinventoryList(cardinventory);
        ExcelUtil<Cardinventory> util = new ExcelUtil<Cardinventory>(Cardinventory.class);
        return util.exportExcel(list, "卡牌库存表数据");
    }

    /**
     * 新增卡牌库存表
     */
    @RequiresPermissions("pims:cardinventory:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存卡牌库存表
     */
    @RequiresPermissions("pims:cardinventory:add")
    @Log(title = "卡牌库存表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Cardinventory cardinventory)
    {
        return toAjax(cardinventoryService.insertCardinventory(cardinventory));
    }

    /**
     * 修改卡牌库存表
     */
    @RequiresPermissions("pims:cardinventory:edit")
    @GetMapping("/edit/{inventoryId}")
    public String edit(@PathVariable("inventoryId") Long inventoryId, ModelMap mmap)
    {
        Cardinventory cardinventory = cardinventoryService.selectCardinventoryByInventoryId(inventoryId);
        mmap.put("cardinventory", cardinventory);
        return prefix + "/edit";
    }

    /**
     * 修改保存卡牌库存表
     */
    @RequiresPermissions("pims:cardinventory:edit")
    @Log(title = "卡牌库存表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Cardinventory cardinventory)
    {
        return toAjax(cardinventoryService.updateCardinventory(cardinventory));
    }

    /**
     * 删除卡牌库存表
     */
    @RequiresPermissions("pims:cardinventory:remove")
    @Log(title = "卡牌库存表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cardinventoryService.deleteCardinventoryByInventoryIds(ids));
    }
}
